package com.yiyuan.app.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.yiyuan.app.entity.po.GConfDevicePO;
import com.yiyuan.app.mapper.GConfDeviceMapper;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;

@Repository
public class GConfDeviceDAO extends BaseDAO<GConfDeviceMapper, GConfDevicePO> {

    public int updateDeviceRepair(Long id, LocalDateTime repairTime) {
        LambdaUpdateWrapper<GConfDevicePO> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(GConfDevicePO::getId, id);
        updateWrapper.set(GConfDevicePO::getRepairTime, repairTime);
        return getBaseMapper().update(new GConfDevicePO(), updateWrapper);
    }

    public GConfDevicePO findOneDeviceNoIsNull() {
        LambdaQueryWrapper<GConfDevicePO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.isNull(GConfDevicePO::getSerialNumber);
        return getBaseMapper().selectOne(queryWrapper);
    }

    public int updateDeviceStatus(String deviceNo, boolean status) {
        LambdaUpdateWrapper<GConfDevicePO> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(GConfDevicePO::getStatus, status);
        updateWrapper.eq(GConfDevicePO::getSerialNumber, deviceNo);
        return getBaseMapper().update(new GConfDevicePO(), updateWrapper);
    }
}
